package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lsq
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController extends BaseController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping
    @ApiOperation(value = "获取所有护理等级", notes = "返回所有护理等级的列表")
    public ResponseResult getAllNursingLevel() {
        List<NursingLevelVo> nursingLevelVoList = nursingLevelService.getAllNursingLevel();
        return success(nursingLevelVoList);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "添加护理等级", notes = "添加一个新的护理等级")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto dto) {
        nursingLevelService.addNursingLevel(dto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "分页查询护理等级", notes = "根据条件分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @ApiParam(value = "护理等级名称", example = "一级护理") String name,
            @ApiParam(value = "状态：0-禁用，1-启用", example = "1") Integer status,
            @ApiParam(value = "当前页码", example = "1")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量", example = "10")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取护理等级", notes = "根据护理等级ID获取详细信息")
    public ResponseResult getById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新护理等级", notes = "根据ID更新护理等级的信息")
    public ResponseResult updateById(@RequestBody NursingLevelDto dto){
        nursingLevelService.updateById(dto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级", notes = "根据ID删除护理等级")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingLevelService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "更新护理等级状态", notes = "根据ID更新护理等级的状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.updateStatus(id, status);
        return success();
    }
}